﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
namespace Apps.Common
{
    public partial class TextWallControl : UserControl
    {
        public const string WALL_STRING = "WALL_STRING";
        public const string WALL_SPLTOR = "WALL_SPLTOR";
        public const string WALL_WIDTH = "WALL_WIDTH";
        public const string WALL_HEIGHT = "WALL_HEIGHT";
        public const string WALL_SPLTOR_DEFAULT = ",";
        public const int WALL_WIDTH_DEFAULT = 1440;
        public const int WALL_HEIGHT_DEFAULT = 900;

        public const string WALL_STRING_DEFAULT = "专题应用,GIS,管网专题,交通专题,旅游专题,环境专题,地理信息,Pipeline,Traffic,Environmental,Traveling,Smartting,Digital,智慧,Geographic Information System,Analysis,Remote Sensing,1101010,Destination";

        /// <summary>
        /// 屏幕的预设尺寸
        /// </summary>
        public double screen_width = 1440;
        /// <summary>
        /// 屏幕的预设尺寸
        /// </summary>
        public double screen_height = 900;
        /// <summary>
        /// 鼠标运动方向
        /// </summary>
        int directionX;
        /// <summary>
        /// 鼠标运动方向
        /// </summary>
        int directionY;
        public string[] texts { get; set; }
        public TextWallControl()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(BackgroundControl_Loaded);
        }
        bool isInitialized = false;
        void BackgroundControl_Loaded(object sender, RoutedEventArgs e)
        {
            if (isInitialized == false)
            {
                isInitialized = true;
                texts = WALL_STRING_DEFAULT.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                Random random = new Random();
                foreach (var v in ParentCanvas.Children)
                {
                    if ((v is Canvas) == false) continue;
                    foreach (var text in (v as Canvas).Children)
                    {
                        if (text is TextBlock)
                        {
                            var textblock = text as TextBlock;
                            //textblock.Foreground = new SolidColorBrush(Colors.Red);
                            textblock.Text = texts[random.Next(0, texts.Length)];
                        }
                    }
                }
            }
        }

        /// <summary>
        /// 获得屏幕的实际高度
        /// </summary>
        private void getSize()
        {
            screen_width = this.ActualWidth;
            screen_height = this.ActualHeight;
        }
        /// <summary>
        /// 获得屏幕的实际高度
        /// </summary>
        /// <param name="sender">LayoutRoot</param>
        /// <param name="e">SizeChangedEventArgs</param>
        private void LayoutRoot_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            getSize();
        }
        /// <summary>
        /// 鼠标运动时，背景墙三层背景按一定比例关系随鼠标运动
        /// </summary>
        /// <param name="sender">LayoutRoot</param>
        /// <param name="e">MouseEventArgs</param>
        private void LayoutRoot_MouseMove(object sender, MouseEventArgs e)
        {
            Point pt = e.GetPosition(this);

            double xPercent = pt.X / screen_width;
            double yPercent = pt.Y / screen_height;

            translate1ControlX.Value = directionX * 600d * xPercent;
            translate1ControlY.Value = directionX * 600d * yPercent;

            translate1AX.Value = directionX * 400d * xPercent;
            translate1AY.Value = directionY * 400d * yPercent;

            translate1BX.Value = directionX * 300d * xPercent;
            translate1BY.Value = directionY * 300d * yPercent;

            translate1CX.Value = directionX * 200d * xPercent;
            translate1CY.Value = directionY * 200d * yPercent;

            sbTranslate1A.Begin();
            sbTranslate1B.Begin();
            sbTranslate1C.Begin();
            sbTranslate1Control.Begin();
        }
        /// <summary>
        /// 计算鼠标运动方向
        /// </summary>
        /// <param name="sender">LayoutRoot</param>
        /// <param name="e">MouseEventArgs</param>
        private void LayoutRoot_MouseEnter(object sender, MouseEventArgs e)
        {
            Point pt = e.GetPosition(this);
            if (pt.X >= 0)
                directionX = -1;
            else
                directionX = 1;
            if (pt.Y >= 0)
                directionY = -1;
            else
                directionY = 1;
        }
    }
}